<?php
/**
 * Created by PhpStorm.
 * User: zyark
 * Date: 2017/8/27
 * Time: 21:13
 */

namespace Home\Logic;


use Common\Utils\Constants;
use Home\Model\Page;

class ClientMoneyLogLogic
{
    /**
     * 分页条件查询
     * @param $map 查询条件
     * @param $pagenumber 页号
     * @param $pagesize 页面大小
     * @return mixed
     */
    public function getByConditionPage($map, $pagenumber, $pagesize)
    {
        $startno = ($pagenumber - 1) * $pagesize;
        $limit = $startno . ',' . $pagesize;//每页的数据数和内容$limit
        $list = D('MoneyLog')->where($map)->limit($limit)->order('id desc')->select();
        foreach ($list as $key=>$value){
            $list[$key]['create_time'] = date('Y年m月d日',$value['create_time']);
            if($value['money_type'] != Constants::MONEY_TYPE_INCOME) {
                $list[$key]['money'] = round($value['money']);
            }
        }
        $data['list'] = $list;
        $count = D('MoneyLog')->where($map)->count();
        $page = new Page($pagenumber, $count, $pagesize);
        $page = (array)$page;//转换为数组
        $data['page'] = $page;
        return $data;
    }
}